package com.woniuxy.productweb.controller;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.model.Result;
import com.woniuxy.core.util.MyJwtUtil;
import com.woniuxy.productdao.model.CoachReserv;
import com.woniuxy.productmodel.dto.CoachReservDto;
import com.woniuxy.productmodel.dto.CoachReservInfoDto;
import com.woniuxy.productservice.service.CoachReservService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 冉杰
 * @since 2024-01-15
 */
@Api(tags = {"私教预约服务接口"})
@RestController
@RequestMapping("/coachReserv")
public class CoachReservController {
    @Autowired
    private CoachReservService coachReservService;

    /**
     * 用户端发起私教预约
     * @param productId 私教产品id
     * @param token 用户登录token
     * @return
     */
    @ApiOperation("用户端发起私教预约")
    @GetMapping("/add")
    public Result<CoachReservDto> addCoachReserv(Integer productId, @RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
        CoachReservDto dto = coachReservService.addCoachReserv(productId,userId);
        return Result.success("用户发起私教预约成功",dto);
    }

    /**
     * 用户端取消私教预约
     * @param coachReservId 预约id
     * @param token 用户登录token
     * @return
     */
    @ApiOperation("用户端取消私教预约")
    @GetMapping("/cancel")
    public Result cancelCoachReserv(Integer coachReservId, @RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
        coachReservService.cancelCoachReserv(coachReservId,userId);
        return Result.success("用户取消私教预约成功");
    }

    /**
     * 用户端查看私教预约
     * @param token 用户登录token
     * @return
     */
    @ApiOperation("用户端查看私教预约")
    @GetMapping("/findByUser")
    public Result<List<CoachReservDto>> findCoachReservByUser(@RequestHeader String token){
        Integer userId = MyJwtUtil.getUserIdByKey(token, "userId");
       List<CoachReservDto> dtos = coachReservService.findCoachReservByUser(userId);
       return Result.success("用户端查看私教预约成功",dtos);
    }
    /**
     * 教练端查看私教预约
     * @param token 教练登录token
     * @return
     */
    @ApiOperation("教练端查看私教预约")
    @GetMapping("/find.coach")
    public Result<List<CoachReservDto>> findCoachReservByCoach(@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        List<CoachReservDto> dtos = coachReservService.findCoachReservByCoach(coachId);
        return Result.success("教练端查看私教预约成功",dtos);
    }

    /**
     * 教练端拒绝私教预约
     * @param coachReservId 预约id
     * @param token 教练登录token
     * @param message 拒绝理由
     * @return
     */
    @ApiOperation("教练端拒绝私教预约")
    @GetMapping("/refuse.coach")
    public Result refuseCoachReserv(String message,Integer coachReservId,@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        coachReservService.refuseCoachReserv(message,coachReservId,coachId);
        return Result.success("教练端拒绝私教预约成功");
    }

    /**
     * 教练端同意私教预约
     * @param coachReservId 预约id
     * @param token 教练登录token
     * @return
     */
    @ApiOperation("教练端同意私教预约")
    @GetMapping("/agree.coach")
    public Result agreeCoachReserv(Integer coachReservId,@RequestHeader String token){
        Integer coachId = MyJwtUtil.getCoachIdByKey(token, "coachId");
        coachReservService.agreeCoachReserv(coachReservId,coachId);
        return Result.success("同意私教预约成功");
    }

    /**
     * 教练端根据预约id查私教预约
     */
    @ApiOperation("教练端根据预约id查私教预约")
    @GetMapping("/findById.coach")
    public Result<CoachReservInfoDto> findCoachReservById(Integer coachReservId){
       CoachReservInfoDto dto =  coachReservService.findCoachReservById(coachReservId);
        return Result.success("教练端根据id查私教预约成功",dto);
    }
}

